/// @tags: 01Trie
#include <cstdio>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 3, bit = 25;

int n, q;
int a[maxn], b[maxn];

int tcnt;
int rt[maxn], siz[maxn * bit];
int ch[maxn * bit][2];

inline void insert(int &x, int y, int val) {
  int cur = x = ++tcnt;
  for (rint i = bit - 1; i >= 0; --i) {
    int c = (val >> i) & 1;
    ch[cur][!c] = ch[y][!c];
    ch[cur][c] = ++tcnt;
    y = ch[y][c], cur = ch[cur][c];
    siz[cur] = siz[y] + 1;
  }
}

inline int query(int cur, int x, int val) {
  int res = 0;
  for (rint i = bit - 1; i >= 0; --i) {
    int c = (x >> i) & 1;
    if ((val >> i) & 1) {
      res += siz[ch[cur][c]];
      cur = ch[cur][c ^ 1];
    } else {
      cur = ch[cur][c];
    }
  }
  return res;
}

inline int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
    if (n * q > 5000 * 5000) {
      insert(rt[i], rt[i - 1], a[i]);
    }
  }
  for (int i = 1; i <= q; ++i) {
    int l, r, c, d;
    cin >> l >> r >> c >> d;
    if (n * q <= 5000 * 5000) {
      int ans = 0;
      for (int j = l; j <= r; ++j) {
        if ((a[j] ^ c) <= std::min(b[j], d)) ++ans;
      }
      cout << ans << '\n';
    } else {
      cout << query(rt[r], c, d) - query(rt[l - 1], c, d) << '\n';
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("island.in", "r", stdin);
  freopen("island.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
